﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCCommon.OAEnums;
using BCDto.OA.Notification.NotificationRecord;
using BCService.OA.Notification.NotificationRecord;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.Notification.NotificationRecord
{
    /// <summary>
    /// OA系统通知记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class NotificationRecordController : ManagementBaseController
    {
        private readonly INotificationRecordService notificationRecordService;

        public NotificationRecordController(INotificationRecordService notificationRecordService)
        {
            this.notificationRecordService = notificationRecordService;
        }

        #region 获取OA系统业务通知记录
        /// <summary>
        ///  获取OA系统业务通知记录
        /// </summary>
        /// <response code="200">获取OA系统业务通知记录</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<NotificationRecordSumViewDto>), 200)]
        public IActionResult BusinessNotification()
        {
            return this.Ok(this.notificationRecordService.GetNotificationList(OARelatedType.Business, OAProcessStatus.Pending));
        }
        #endregion

        #region 获取OA系统任务通知记录
        /// <summary>
        ///  获取OA系统任务通知记录
        /// </summary>
        /// <response code="200">获取OA系统业务通知记录</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<NotificationRecordSumViewDto>), 200)]
        public IActionResult TaskNotification()
        {
            return this.Ok(this.notificationRecordService.GetNotificationList(OARelatedType.Task, OAProcessStatus.Pending));
        }
        #endregion

        #region 获取OA系统通知记录
        /// <summary>
        ///  获取OA系统通知记录
        /// </summary>
        /// <param name="notificationRecordId">OA系统通知记录Id</param>
        /// <response code="200">获取OA系统通知记录</response>
        /// <returns></returns>
        [HttpGet("{notification_record_id}")]
        [ProducesResponseType(typeof(NotificationRecordDto), 200)]
        public IActionResult Get([FromRoute(Name = "notification_record_id")]long notificationRecordId)
        {
            return this.Ok(this.notificationRecordService.GetEntity(notificationRecordId));
        }
        #endregion

        #region 获取OA系统通知记录（分页）
        /// <summary>
        ///  获取OA系统通知记录（分页）
        /// </summary>
        /// <param name="type">相关类型</param>
        /// <param name="status">处理状态</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统通知记录（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NotificationRecordDto>), 200)]
        public IActionResult Query([FromQuery(Name = "type")]OARelatedType type,
            [FromQuery(Name = "status")]OAProcessStatus status,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.notificationRecordService.Query(type, status, start,end,pageIndex, pageSize));
        }
        #endregion

        #region 开始处理通知
        /// <summary>
        ///  开始处理通知
        /// </summary>
        /// <param name="notificationRecordId">通知记录Id</param>
        /// <response code="200">开始处理通知成功</response>
        /// <returns></returns>
        [HttpPut("[action]/{notification_record_id}")]
        [Log("开始处理通知")]
        [ProducesResponseType(typeof(NotificationRecordDto), 200)]
        public IActionResult StartHandle([FromRoute(Name = "notification_record_id")]long notificationRecordId)
        {
            return this.Ok(this.notificationRecordService.StartHandleNotification(notificationRecordId));
        }
        #endregion

        #region 更新记录通知为已处理
        /// <summary>
        ///  更新记录通知为已处理
        /// </summary>
        /// <param name="notificationRecordId">通知记录Id</param>
        /// <response code="200">更新记录通知为已处理成功</response>
        /// <returns></returns>
        [HttpPut("[action]/{notification_record_id}")]
        [Log("开始处理通知")]
        [ProducesResponseType(typeof(NotificationRecordDto), 200)]
        public IActionResult Handled([FromRoute(Name = "notification_record_id")]long notificationRecordId)
        {
            return this.Ok(this.notificationRecordService.HandledNotification(notificationRecordId));
        }
        #endregion

        #region 关闭通知
        /// <summary>
        ///  关闭通知
        /// </summary>
        /// <param name="closeDto">关闭信息</param>
        /// <response code="200">关闭通知成功</response>
        /// <returns></returns>
        [HttpPut("[action]")]
        [Log("关闭通知")]
        [ProducesResponseType(typeof(NotificationRecordDto), 200)]
        public IActionResult Close([FromBody]NotificationRecordCloseDto closeDto)
        {
            return this.Ok(this.notificationRecordService.CloseNotification(closeDto));
        }
        #endregion
    }
}
